<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>简单轮播图</title>
<style>
    body {
        font-family: Arial, sans-serif;
        text-align: center;
    }
    #slideshow {
        max-width: 600px;
        margin: 0 auto;
        position: relative;
    }
    .slide {
        display: none;
        position: absolute;
        width: 100%;
        height: 300px;
    }
    img {
        max-width: 200%;
        max-height: 200%;
        width: auto;
        height: auto;
    }
    .prev, .next {
        cursor: pointer;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 30px;
        height: 30px;
        background-color: rgba(0, 0, 0, 0.5);
        color: white;
        line-height: 30px;
        text-align: center;
        margin-top: 50%; /* 垂直居中 */
    }
    .prev {
        left: 0;
    }
    .next {
        right: 0;
    }
</style>
</head>
<body>
<div id="slideshow">
    <div class="slide">
        <img src="static/images/胡歌1.jpg" alt="Slide 1">
    </div>
    <div class="slide">
        <img src="static/images/胡歌2.jpg" alt="Slide 2">
    </div>
    <div class="slide">
        <img src="static/images/刘亦菲.jpeg" alt="Slide 3">
    </div>
    <div class="slide">
        <img src="static/images/favicon.ico" alt="Slide 4">
    </div>
    <div class="prev" onclick="prevSlide()">❮</div>
    <div class="next" onclick="nextSlide()">❯</div>
</div>

<script>
let currentSlide = 0;
const slides = document.querySelectorAll('.slide');

function showSlide(slideIndex) {
    if (slideIndex >= slides.length) {
        currentSlide = 0;
    } else if (slideIndex < 0) {
        currentSlide = slides.length - 1;
    } else {
        currentSlide = slideIndex;
    }

    for (let i = 0; i < slides.length; i++) {
        slides[i].style.display = 'none';
    }

    slides[currentSlide].style.display = 'block';
}

function nextSlide() {
    showSlide(currentSlide + 1);
}

function prevSlide() {
    showSlide(currentSlide - 1);
}

showSlide(currentSlide);
setInterval(nextSlide, 3000); // 自动播放间隔时间（毫秒）

</script>
</body>
</html>
